const express = require('express')
const app = express()
const path = require('path')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const {createProxyMiddleware} = require('http-proxy-middleware')

// 设置静态资源的访问
app.use(express.static(path.join(__dirname, 'src')))
app.use(express.static(path.join(__dirname, '../')))
// 将参数转换成对象
app.use(bodyParser.urlencoded({extended: true}))
app.use(cookieParser())
// 中间件代理
app.use('/api/middleware', createProxyMiddleware({
  target: 'http://child.cross.com:6000',
  changeOrigin: true
}))

app.listen(3000, function(req, res) {
  console.log("请打开http://localhost:3000/jsonp/jsonp.html访问页面")
})